package cn.huanba.config;

import cn.huanba.filter.CustomGatewayFilter;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 网关路由配置
 */
@Configuration
public class GatewayRoutesConfiguration {
    //@Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder) {
        return builder.routes().route(r -> r
                //断言
                .path("/**")
                //目标地址  路由到微服务的地址
                .uri("lb://huanba-consumer")
                //注册自定义网关过滤器
                .filters(new CustomGatewayFilter())
                //唯一的路由id
                .id("dict-service")
        ).build();
    }
}
